/**
 * JMPlurk, a Java Mobile client for Plurk
 * Copyright (C) 2009 Petra Barus
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package com.maleskoding.jmplurk.plurkapi;

import com.sun.me.web.path.Result;
import com.sun.me.web.request.Arg;
import com.sun.me.web.request.Request;
import com.sun.me.web.request.RequestListener;
import com.sun.me.web.request.Response;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import org.json.me.JSONException;
import org.json.me.JSONObject;

/**
 * @author Petra Barus
 * * Based on http://www.plurk.com/API/issueKey
 */
public class PlurkAPI {

    private User user;
    private String userid;
    private String username;
    private String password;
    private String cookiestring = "";
    //
    private RequestListener requestlistener;
    //
    private boolean isLoggedIn = false;
    //
    private final static String API_KEY = "4rf42U17qrhC46nSHsjcXLyj1UDo62pA";
    private final static String BASE_URL = "http://www.plurk.com/API/";
    private final static String BASE_URL_HTTPS = "http://www.plurk.com/API/";
    private final static String USERS_REGISTER = BASE_URL + "Users/register";
    private final static String USERS_LOGIN = BASE_URL_HTTPS + "Users/login";
    private final static String USERS_UPDATE_PICTURE = BASE_URL + "Users/updatePicture";
    private final static String USERS_UPDATE = BASE_URL + "Users/update";
    private final static String POLLING_GET_PLURKS = BASE_URL + "Polling/getPlurks";
    private final static String POLLING_GET_UNREAD_COUNT = BASE_URL + "Polling/getUnreadCount";
    private final static String TIMELINE_GET_PLURK = BASE_URL + "Timeline/getPlurk";
    private final static String TIMELINE_GET_PLURKS = BASE_URL + "Timeline/getPlurks";
    private final static String TIMELINE_UNREAD_PLURKS = BASE_URL + "Timeline/getUnreadPlurks";
    private final static String TIMELINE_MUTE_PLURKS = BASE_URL + "Timeline/mutePlurks";
    private final static String TIMELINE_UNMUTE_PLURKS = BASE_URL + "Timeline/unmutePlurks";
    private final static String TIMELINE_MARK_AS_READ = BASE_URL + "Timeline/markAsRead";
    private final static String TIMELINE_PLURK_ADD = BASE_URL + "Timeline/plurkAdd";
    private final static String TIMELINE_UPLOAD_PICTURE = BASE_URL + "Timeline/uploadPicture";
    private final static String TIMELINE_PLURK_DELETE = BASE_URL + "Timeline/plurkDelete";
    private final static String TIMELINE_PLURK_EDIT = BASE_URL + "Timeline/plurkEdit";
    private final static String RESPONSES_GET = BASE_URL + "Responses/get";
    private final static String RESPONSES_RESPONSE_ADD = BASE_URL + "Responses/responseAdd";
    private final static String RESPONSES_RESPONSE_DELETE = BASE_URL + "Responses/responseDelete";
    private final static String PROFILE_GET_OWN_PROFILE = BASE_URL + "Profile/getOwnProfile";
    private final static String PROFILE_GET_PUBLIC_PROFILE = BASE_URL + "Profile/getPublicProfile";
    private final static String FRIENDS_FANS_GET_FRIENDS_BY_OFFSET = BASE_URL + "FriendsFans/getFriendsByOffset";
    private final static String FRIENDS_FANS_GET_FANS_BY_OFFSET = BASE_URL + "FriendsFans/getFansByOffset";
    private final static String FRIENDS_FANS_GET_FOLLOWING_BY_OFFSET = BASE_URL + "FriendsFans/getFollowingByOffset";
    private final static String FRIENDS_FANS_BECOME_FRIEND = BASE_URL + "FriendsFans/becomeFriend";
    private final static String FRIENDS_FANS_REMOVE_AS_FRIEND = BASE_URL + "FriendsFans/removeAsFriend";
    private final static String FRIENDS_FANS_BECOME_FAN = BASE_URL + "FriendsFans/becomeFan";
    private final static String FRIENDS_FANS_SET_FOLLOWING = BASE_URL + "FriendsFans/setFollowing";
    private final static String FRIENDS_FANS_GET_COMPLETION = BASE_URL + "FriendsFans/getCompletion";
    private final static String ALERTS_GET_ACTIVE = BASE_URL + "Alerts/getActive";
    private final static String ALERTS_GET_HISTORY = BASE_URL + "Alerts/getHistory";
    private final static String ALERTS_ADD_AS_FAN = BASE_URL + "Alerts/addAsFan";
    private final static String ALERTS_ADD_ALL_AS_FAN = BASE_URL + "Alerts/addAllAsFan";
    private final static String ALERTS_ADD_ALL_AS_FRIENDS = BASE_URL + "Alerts/addAllAsFriends";
    private final static String ALERTS_ADD_AS_FRIEND = BASE_URL + "Alerts/addAsFriend";
    private final static String ALERTS_DENY_FRIENDSHIP = BASE_URL + "Alerts/denyFriendship";
    private final static String ALERTS_REMOVE_NOTIFICATION = BASE_URL + "Alerts/removeNotification";
    private final static String PLURK_SEARCH = BASE_URL + "PlurkSearch/search";
    private final static String USER_SEARCH = BASE_URL + "UserSearch/search";
    private final static String EMOTICONS_GET = BASE_URL + "Emoticons/get";
    private final static String BLOCKS_GET = BASE_URL + "Blocks/get";
    private final static String BLOCKS_BLOCK = BASE_URL + "Blocks/block";
    private final static String BLOCKS_UNBLOCK = BASE_URL + "Blocks/unblock";
    private final static String CLIQUES_GET_CLIQUES = BASE_URL + "Cliques/get_cliques";
    private final static String CLIQUES_CREATE_CLIQUES = BASE_URL + "Cliques/create_clique";
    private final static String CLIQUES_GET_CLIQUE = BASE_URL + "Cliques/get_clique";
    private final static String CLIQUES_RENAME_CLIQUES = BASE_URL + "Cliques/rename_clique";

    /**
     * 
     */
    public PlurkAPI() {
        this.requestlistener = null;
    }

    /**
     * 
     * @param url
     * @param args
     * @return
     * @throws PlurkException
     * @throws IOException
     */
    private Result sendRequest(String url, Arg[] args) throws PlurkException, IOException {
        Response response;
        if (cookiestring.length() > 0) {
            Arg[] ar = {
                new Arg("cookie", cookiestring),};
            response = Request.get(url, args, ar, requestlistener);
        } else {
            response = Request.get(url, args, null, requestlistener);
        }
        Arg[] ar = response.getHeaders();
        for (int i = 0; i < ar.length; i++) {
            String s = ar[i].getKey();
            s.toLowerCase();
            if (s.equals("set-cookie")) {
                cookiestring = ar[i].getValue();
            }
        }
        Result result = response.getResult();
        if (response.getCode() == 200) {
            return result;
        } else if (response.getCode() == 400) {
            throw new PlurkException();
        } else {
            throw new PlurkException();
        }
    }

    //<editor-fold defaultstate="collapsed" desc="Users">
    /**
     * 
     * @param username
     * @param password
     */
    public PlurkAPI(String username, String password) {
        this();
        this.username = username;
        this.password = password;
    }

    /**
     * Login an already created user. Login creates a session cookie,
     * which can be used to access the other methods. On success it
     * returns the data returned by /API/Profile/getOwnProfile.
     * Should be HTTPS
     */
    public JSONObject login() throws PlurkException, IOException {
        String url = USERS_LOGIN;
        final Arg[] args = {
            new Arg("api_key", API_KEY),
            new Arg("username", username),
            new Arg("password", password)
        };
        System.err.println("Logging to Plurk..");
        Result r = sendRequest(url, args);
        //System.err.println(r.toString());
        try {
            JSONObject retval = new JSONObject(r.toString());
            JSONObject jsonuser = retval.getJSONObject("user_info");
            userid = jsonuser.getString("id");
            System.out.println(userid);
            //user = new User(retval.getJSONObject("user_info"));
            return retval;
        } catch (JSONException ex) {
            return null;
        }
    }

    /**
     * Login an already created user. Login creates a session cookie,
     * which can be used to access the other methods. On success it
     * returns the data returned by /API/Profile/getOwnProfile.
     * Should be HTTPS
     * @param username
     * @param password
     */
    public JSONObject login(String username, String password) throws PlurkException, IOException {
        this.username = username;
        this.password = password;
        return login();
    }
    //</editor-fold>
    //
    //<editor-fold defaultstate="collapsed" desc="Timeline">

    /**
     * 
     */
    public JSONObject getPlurk(String plurk_id) throws PlurkException, IOException, JSONException {
        String url = TIMELINE_GET_PLURK;
        final Arg[] args = {
            new Arg("api_key", API_KEY),
            new Arg("plurk_id", plurk_id)
        };
        Result r = sendRequest(url, args);
        return new JSONObject(r.toString());
    }

    /**
     * 
     * @return
     * @throws PlurkException
     * @throws IOException
     * @throws JSONException
     */
    public JSONObject getPlurks(String offset, String limit, String only_responded, String only_private) throws PlurkException, IOException, JSONException {
        String url = TIMELINE_GET_PLURKS;
        final Arg[] args = {
            new Arg("api_key", API_KEY),
            new Arg("offset", offset),
            new Arg("limit", limit),
            new Arg("only_responded", only_responded),
            new Arg("only_private", only_private)
        };
        Result r = sendRequest(url, args);
        return new JSONObject(r.toString());
    }

    //<editor-fold defaultstate="collapsed" desc="Unused">
//    /**
//     *
//     * @return
//     * @throws PlurkException
//     * @throws IOException
//     * @throws JSONException
//     */
//    public JSONObject getPlurks(String offset) throws PlurkException, IOException, JSONException {
//        String url = TIMELINE_GET_PLURKS;
//        final Arg[] args = {
//            new Arg("api_key", API_KEY),
//            new Arg("offset", offset)
//        };
//        Result r = sendRequest(url, args);
//        return new JSONObject(r.toString());
//    }
//
//    /**
//     *
//     * @return
//     * @throws PlurkException
//     * @throws IOException
//     * @throws JSONException
//     */
//    public JSONObject getPrivatePlurks() throws PlurkException, IOException, JSONException {
//        return getPlurks(getCurrentTime(), "20", "false", "true");
//    }
//
//    /**
//     *
//     * @param offset
//     * @return
//     * @throws PlurkException
//     * @throws IOException
//     * @throws JSONException
//     */
//    public JSONObject getPrivatePlurks(String offset) throws PlurkException, IOException, JSONException {
//        return getPlurks(offset, "20", "false", "true");
//    }
//
//    /**
//     *
//     * @param offset
//     * @param limit
//     * @return
//     * @throws PlurkException
//     * @throws IOException
//     * @throws JSONException
//     */
//    public JSONObject getPrivatePlurks(String offset, String limit) throws PlurkException, IOException, JSONException {
//        String url = TIMELINE_GET_PLURKS;
//        final Arg[] args = {
//            new Arg("api_key", API_KEY),
//            new Arg("offset", offset),
//            new Arg("limit", limit),
//            new Arg("only_private", "true")
//        };
//        Result r = sendRequest(url, args);
//        return new JSONObject(r.toString());
//    }
//
//    /**
//     *
//     * @param offset
//     * @param limit
//     * @return
//     * @throws PlurkException
//     * @throws IOException
//     * @throws JSONException
//     */
//    public JSONObject getRespondedPlurks() throws PlurkException, IOException, JSONException {
//        return getRespondedPlurks(getCurrentTime());
//    }
//
//    /**
//     *
//     * @param offset
//     * @return
//     * @throws PlurkException
//     * @throws IOException
//     * @throws JSONException
//     */
//    public JSONObject getRespondedPlurks(String offset) throws PlurkException, IOException, JSONException {
//        return getRespondedPlurks(offset, "20");
//    }
//
//    /**
//     *
//     * @param offset
//     * @param limit
//     * @return
//     * @throws PlurkException
//     * @throws IOException
//     * @throws JSONException
//     */
//    public JSONObject getRespondedPlurks(String offset, String limit) throws PlurkException, IOException, JSONException {
//        String url = TIMELINE_GET_PLURKS;
//        final Arg[] args = {
//            new Arg("api_key", API_KEY),
//            new Arg("offset", offset),
//            new Arg("limit", limit),
//            new Arg("only_responded", "true")
//        };
//        Result r = sendRequest(url, args);
//        return new JSONObject(r.toString());
//    }
//
//    public JSONObject getPlurksByUser(String offset, String userid) throws PlurkException, JSONException, IOException {
//        String url = TIMELINE_GET_PLURKS;
//        final Arg[] args = {
//            new Arg("api_key", API_KEY),
//            new Arg("offset", offset),
//            new Arg("only_user", userid)
//        };
//        Result r = sendRequest(url, args);
//        return new JSONObject(r.toString());
//    }
//
//    /**
//     *
//     */
//    public JSONObject getMyPlurks(String offset) throws PlurkException, JSONException, IOException {
//        String url = TIMELINE_GET_PLURKS;
//        final Arg[] args = {
//            new Arg("api_key", API_KEY),
//            new Arg("offset", offset),
//            new Arg("only_user", this.userid)
//        };
//        Result r = sendRequest(url, args);
//        return new JSONObject(r.toString());
//    }
//
//    /**
//     *
//     */
//    public JSONObject getUnreadPlurks(String offset, String limit) throws PlurkException, IOException, JSONException {
//        String url = TIMELINE_UNREAD_PLURKS;
//        final Arg[] args = {
//            new Arg("api_key", API_KEY),
//            new Arg("offset", offset),
//            new Arg("limit", limit)
//        };
//        Result r = sendRequest(url, args);
//        return new JSONObject(r.toString());
//    }
//
//    /**
//     *
//     * @param offset
//     * @return
//     * @throws PlurkException
//     * @throws JSONException
//     * @throws IOException
//     */
//    public JSONObject getUnreadPlurks(String offset) throws PlurkException, JSONException, IOException {
//        String url = TIMELINE_UNREAD_PLURKS;
//        final Arg[] args = {
//            new Arg("api_key", API_KEY),
//            new Arg("offset", offset)
//        };
//        Result r = sendRequest(url, args);
//        return new JSONObject(r.toString());
//    }
//
//    public JSONObject getUnreadPlurks(int limit) {
//        return null;
//    }
//
//    /**
//     *
//     * @return
//     * @throws PlurkException
//     * @throws JSONException
//     * @throws IOException
//     */
//    public JSONObject getUnreadPlurks() throws PlurkException, JSONException, IOException {
//        return getUnreadPlurks(getCurrentTime());
//    }
    //</editor-fold>
    /**
     * 
     */
    public void mutePlurks() {
        String url = TIMELINE_MUTE_PLURKS;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void unmutePlurks() {
        String url = TIMELINE_UNMUTE_PLURKS;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void markAsRead() {
        String url = TIMELINE_MARK_AS_READ;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     * @param content
     * @param qualifier
     * @throws PlurkException
     * @throws IOException
     */
    public void addPlurk(String content, String qualifier) throws PlurkException, IOException {
        String url = TIMELINE_PLURK_ADD;
        final Arg[] args = {
            new Arg("api_key", API_KEY),
            new Arg("content", content),
            new Arg("qualifier", qualifier)
        };
        Result r = sendRequest(url, args);
    }

    /**
     * 
     * @param content
     * @param qualifier
     * @param lang
     * @throws PlurkException
     * @throws IOException
     */
    public void addPlurk(String content, String qualifier, String lang) throws PlurkException, IOException {
        String url = TIMELINE_PLURK_ADD;
        final Arg[] args = {
            new Arg("api_key", API_KEY),
            new Arg("content", content),
            new Arg("qualifier", qualifier),
            new Arg("lang", lang)
        };
        Result r = sendRequest(url, args);
    }

    /**
     * 
     */
    public void uploadPicture() {
        String url = TIMELINE_UPLOAD_PICTURE;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void deletePlurk() {
        String url = TIMELINE_PLURK_DELETE;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void editPlurk() {
        String url = TIMELINE_PLURK_EDIT;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }
    //
    //</editor-fold>
    //
    //<editor-fold defaultstate="collapsed" desc="Polling">

    /**
     *
     */
    public JSONObject getPollingPlurks(String offset) throws PlurkException, IOException, JSONException {
        String url = POLLING_GET_PLURKS;
        final Arg[] args = {
            new Arg("api_key", API_KEY),
            new Arg("offset", offset)
        };
        Result r = sendRequest(url, args);
        return new JSONObject(r.toString());
    }

    public JSONObject getPollingUnreadCount() throws PlurkException, JSONException, IOException {
        String url = POLLING_GET_UNREAD_COUNT;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        Result r = sendRequest(url, args);
        return new JSONObject(r.toString());
    }

    /**
     * 
     */
    //</editor-fold>
    //
    //<editor-fold defaultstate="collapsed" desc="Responses">
    /**
     * 
     */
    public JSONObject getResponses(String plurk_id) throws PlurkException, JSONException, IOException {
        String url = RESPONSES_GET;
        final Arg[] args = {
            new Arg("api_key", API_KEY),
            new Arg("plurk_id", plurk_id)
        };
        Result r = sendRequest(url, args);
        return new JSONObject(r.toString());
    }

    /**
     *
     */
    public JSONObject getResponses(String plurk_id, String from_response) throws PlurkException, JSONException, IOException {
        String url = RESPONSES_GET;
        final Arg[] args = {
            new Arg("api_key", API_KEY),
            new Arg("plurk_id", plurk_id),
            new Arg("from_response", from_response)
        };
        Result r = sendRequest(url, args);
        return new JSONObject(r.toString());
    }

    /**
     * 
     */
    public JSONObject addResponse(String plurk_id, String content, String qualifier) throws PlurkException, IOException, JSONException {
        String url = RESPONSES_RESPONSE_ADD;
        final Arg[] args = {
            new Arg("api_key", API_KEY),
            new Arg("plurk_id", plurk_id),
            new Arg("content", content),
            new Arg("qualifier", qualifier)
        };
        Result r = sendRequest(url, args);
        return new JSONObject(r.toString());
    }

    /**
     * 
     */
    public void deleteResponse() {
        String url = RESPONSES_RESPONSE_DELETE;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }
    //</editor-fold>
    //
    //<editor-fold defaultstate="collapsed" desc="Profile">

    /**
     *
     */
    public void getOwnProfile() {
        String url = PROFILE_GET_OWN_PROFILE;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void getPublicProfile() {
        String url = PROFILE_GET_PUBLIC_PROFILE;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }
    //</editor-fold>
    //
    //<editor-fold defaultstate="collapsed" desc="Friends and Fans">  

    /**
     * 
     */
    public void getFriendsByOffset() {
        String url = FRIENDS_FANS_GET_FRIENDS_BY_OFFSET;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     */
    public void getFansByOffset() {
        String url = FRIENDS_FANS_GET_FANS_BY_OFFSET;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void getFollowingByOffset() {
        String url = FRIENDS_FANS_GET_FOLLOWING_BY_OFFSET;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void becomeFriend() {
        String url = FRIENDS_FANS_BECOME_FRIEND;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void removeAsFriend() {
        String url = FRIENDS_FANS_REMOVE_AS_FRIEND;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     */
    public void becomeFan() {
        String url = FRIENDS_FANS_BECOME_FAN;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     */
    public void setFollowing() {
        String url = FRIENDS_FANS_SET_FOLLOWING;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     */
    public void getCompletion() {
        String url = FRIENDS_FANS_GET_COMPLETION;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }
    //</editor-fold>
    //
    //<editor-fold defaultstate="collapsed" desc="Alerts">

    /**
     * Return list of current active alerts.
     * Requires login
     */
    public void getActiveAlert() {
        String url = ALERTS_GET_ACTIVE;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * Return a list of past 30 alerts.
     * Requires login
     */
    public void getAlertHistory() {
        String url = ALERTS_GET_HISTORY;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void getAddAsFanAlert() {
        String url = ALERTS_ADD_AS_FAN;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void getAllAddAsFanAlerts() {
        String url = ALERTS_ADD_ALL_AS_FAN;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void getAddAsFriendAlert() {
        String url = ALERTS_ADD_AS_FRIEND;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void getAllAdAsFriendAlert() {
        String url = ALERTS_ADD_ALL_AS_FRIENDS;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void getDenyFriendshipAlert() {
        String url = ALERTS_DENY_FRIENDSHIP;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void removeNotification() {
        String url = ALERTS_REMOVE_NOTIFICATION;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }
    //</editor-fold>
    //
    //<editor-fold defaultstate="collapsed" desc="Search">

    /**
     * Returns the latest 20 plurks on a search term. 
     */
    public void searchPlurk() {
        String url = PLURK_SEARCH;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * Returns the latest 20 plurks on a search term.
     */
    public void searchUser() {
        String url = USER_SEARCH;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }
    //</editor-fold>
    //
    //<editor-fold defaultstate="collapsed" desc="Emoticons">

    /**
     * 
     */
    public void getEmoticons() {
        String url = EMOTICONS_GET;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }
    //</editor-fold>
    //
    //<editor-fold defaultstate="collapsed" desc="Blocks">

    /**
     *
     */
    public void getBlocks() {
        String url = BLOCKS_GET;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void blockUser() {
        String url = BLOCKS_BLOCK;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     */
    public void unblockUser() {
        String url = BLOCKS_UNBLOCK;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }
    //</editor-fold>
    //
    //<editor-fold defaultstate="collapsed" desc="Cliques">

    /**
     * 
     */
    public void getCliques() {
        String url = CLIQUES_GET_CLIQUES;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void createCliques() {
        String url = CLIQUES_CREATE_CLIQUES;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     */
    public void getClique() {
        String url = CLIQUES_GET_CLIQUE;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     */
    public void renameClique() {
        String url = CLIQUES_RENAME_CLIQUES;
        final Arg[] args = {
            new Arg("api_key", API_KEY)
        };
        //TODO: Complete!
        throw new UnsupportedOperationException("Not supported yet.");
    }

    //</editor-fold>
    //
    //<editor-fold defaultstate="collapsed" desc="">
    public RequestListener getRequestlistener() {
        return requestlistener;
    }

    public void setRequestlistener(RequestListener requestlistener) {
        this.requestlistener = requestlistener;
    }
    //</editor-fold>

    public static String getCurrentTime() {
        //TODO: Implement
        Calendar c = Calendar.getInstance();
        Date d = new Date();
        c.setTime(d);
        String s = c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1) + "-" + (c.get(Calendar.DAY_OF_MONTH)) + "T" + c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND);
        return s;
    }
}
